﻿<%@ Page Title="Position" Language="C#" MasterPageFile="~/Posts/Posts.master" AutoEventWireup="true" CodeFile="Position.aspx.cs" Inherits="Posts_Position" %>
<%@ Register Src="Header.ascx" TagPrefix="uc" TagName="Header"  %>
<asp:Content ID="contentHead" ContentPlaceHolderID="phHead" runat="server">
    <script language="javascript">
        /*var nodeDragStart = function(obj, e) {
            disableNodes(obj.get_nodes(), e.get_node());
        }

        var disableNodes = function(nodes, currentNode) {
            for (var i = 0; i < nodes.get_count(); i++) {
                var node = nodes.getNode(i);
                if (node != currentNode) {
                    node.disable();
                    //node.set_allowDrop(false);
                    disableNodes(node.get_nodes(), currentNode);
                }
            }
        }

        var nodeDropped = function(obj, e) {
            enableNodes(obj.get_nodes());
        }

        var nodeClicked = function(obj, e) {
            enableNodes(obj.get_nodes());
        }

        var enableNodes = function(nodes) {
            for (var i = 0; i < nodes.get_count(); i++) {
                var node = nodes.getNode(i);
                node.enable();
                //node.set_allowDrop(true);
                enableNodes(node.get_nodes());
            }
        }*/
        
        var dragging = false; 
        var lastHoveredNode = null; 
         
        function clientNodeDragging(sender, eventArgs) { 
            var node = sender._extractNodeFromDomElement(eventArgs.get_htmlElement()); 
             
            if (node) { 
                if((node.get_parent().get_allowDrop) &&  
                   (node.get_parent().get_allowDrop() == false)) { 
                    if(sender._draggingPosition != "over") { 
                        sender._dropClue.style.cursor = "not-allowed"; 
                        node.get_element().style.cursor = "not-allowed"; 
                         
                        if ((lastHoveredNode) && 
                            (lastHoveredNode != node)) { 
                            lastHoveredNode.get_element().style.cursor = "default"; 
                        } 
                         
                        lastHoveredNode = node; 
                    } 
                    else { 
                        node.get_element().style.cursor = "default"; 
                    } 
                } 
            } 
        } 
         
        function clientNodeDropping(sender, eventArgs) { 
            var destNode = eventArgs.get_destNode(); 
            var sourceNode = eventArgs.get_sourceNode();

            if ((destNode.get_parent().get_allowDrop) &&
               (destNode.get_parent().get_allowDrop() == false) &&
               (eventArgs.get_dropPosition() != "over")) {
                eventArgs.set_cancel(true);
                if (lastHoveredNode) {
                    lastHoveredNode.get_element().style.cursor = "default";
                }
            }
            else if (destNode == sourceNode.get_parent() && eventArgs.get_dropPosition() == "over") {
                eventArgs.set_cancel(true);
                if (lastHoveredNode) {
                    lastHoveredNode.get_element().style.cursor = "default";
                }
            }
            
        } 
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="phMain" Runat="Server">
    <ajax:Accordion ID="accordianTitle" SkinID="Title" runat="server">
        <Panes>
            <ajax:AccordionPane ID="accordianPaneTitle" runat="server">
                <Header>
                    <asp:Label ID="lblTitle" runat="server"></asp:Label>
                </Header>
                <Content>
                    To move posts around drag and drop them with in the tree.
                </Content>
            </ajax:AccordionPane>
        </Panes>
    </ajax:Accordion>
    <uc:Header ID="ucHeader" runat="server" />
    <asp:Panel ID="pnlWrapper" CssClass="tabPage" runat="server">
        <telerik:RadTreeView ID="tvMap" Skin="Web20" EnableDragAndDrop="true" EnableDragAndDropBetweenNodes="true" OnClientNodeDropping="clientNodeDropping" OnClientNodeDragging="clientNodeDragging" DataSourceID="dsSiteMap" runat="server">
            <DataBindings>
                <telerik:RadTreeNodeBinding TextField="DisplayName" ValueField="Id" ToolTipField="TemplateName"/>
            </DataBindings>
        </telerik:RadTreeView>
    </asp:Panel>
    <acms:AcmsSiteMapDataSource ID="dsSiteMap" runat="server" />
</asp:Content>

